<!DOCTYPE html>
<html>
<head>
    <title>自己的电商系统</title>
    <meta charset="utf-8">
    <link rel="stylesheet" href="__PUBLIC__/css/bootstrap.min.css" />
    <link rel="stylesheet" href="__PUBLIC__/css/bootstrap-theme.min.css" />
    <link rel="stylesheet" href="__PUBLIC__/css/front.css" />
</head>
<body>
    <div class="container shopcart">
        <div class="row">
            <div class="col-md-3"><a href="<?php echo U('home/front/index') ?>"><img id="logo" src="__PUBLIC__/img/logo.jpg"></a>
            </div>
            <div class=" col-md-9">
                <img style="height:50px; margin-top:40px" class="pull-right" src="__PUBLIC__/img/shop_step_2.jpg ">
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <h3>收货地址<button class="btn btn-info btn-xs pull-right" id="addAddress">添加地址</button></h3>
                <hr/>
                <form action="<?php echo U('home/shoping/do_createorder') ?>" method="post">
                    <table class="table table-bordered table-hover">
                        <?php foreach ($address as $a) { ?>
                          <tr>
                            <td class='text-center'><input type='radio' name="address_id" value="<?=$a['id'] ?>"></td>
                            <td class='text-center'>收件人：<?=$a['name'] ?></td>
                            <td class='text-center'>地址：<?=$a['address'] ?></td>
                            <td class='text-center'>联系方式：<?=$a['phone'] ?></td>
                            <td class='text-center'><button class="btn btn-danger btn-xs" id="del">删除</button></td>
                        </tr>
                        <?php
                            } 
                        ?>  
                    </table>
                    <hr/>
                    <table id="top" class="table table-bordered table-hover"> 
                         <tr class="tp">
                            <th width="30%">商品</th>
                            <th width="20%%">单价</th>
                            <th width="20%">数量</th>
                            <th width="20%">小计（元）</th>     
                        </tr>
                        <?php  $i=0; foreach($data as $c ) {
                            $prodect=M('prodect')->where('id='.$c['prodect_id'])->find(); 
                        ?>
                        <tr class="bottom">
                            <input type="hidden" value="<?=$prodect['id'] ?>" name="prodect_id[]"> 
                             <input type="hidden" value="<?=$c['num'] ?>" name="num[]"> 
                            <td ><a  href="<?php echo U('home/prodect/detail/id/'.$prodect['id']) ?>"><img style="height:60px;" src="__ROOT__<?php echo $prodect['img'] ?>"><?php echo $prodect['title'] ?></a></td>
                            <td >￥<?php echo number_format($prodect['price'],2) ?></td>
                            <td ><?php echo $c['num'] ?></td>
                            <td ><?php echo $n=intval($prodect['price'])*(int)$c['num'] ?></td> 
                        </tr>    
                        <?php
                            $i++;
                            } 
                        ?> 
                    </table>
                    <button type="submit" class="btn btn-danger">提交订单</button>
                </form>
            </div>
        </div>  
    </div>
    <div class="modal fade" id="model">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">增加收货地址</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label >姓名</label>
                        <input type="input" class="form-control"  placeholder=" 请输入姓名" name="name">
                    </div>
                    <div class="form-group">
                        <label >地址</label>
                        <textarea  class="form-control"  placeholder="请输入地址" name="address"></textarea>
                    </div>
                    <div class="form-group">
                        <label >号码</label>
                        <input type="input" class="form-control"  placeholder=" 请输入号码" name="phone">
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="saveAddress">保存</button>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="__PUBLIC__/js/jquery.min.js"></script> 
    <script type="text/javascript" src="__PUBLIC__/js/bootstrap.min.js"></script>    
    <script type="text/javascript">
        $(window).load(function(){
            $('#addAddress').click(function(){
                $('#model').modal('show');   
            });
               $("#saveAddress").click(function(){
                 var name= $('#model [name="name"]').val();
                var address= $('#model [name="address"]').val();
                var phone= $('#model [name="phone"]').val();
                $.post('<?=U("home/shoping/saveaddress") ?>',{
                    name:name,
                    address:address,
                    phone:phone
                },function(data){
                    data=eval("("+data+')');
                    if(data.code=='error'){$('#model [name="'+data.field+'"]').after('<p class="error">'+data.msg+'</p>')};
                    if(data.code=='ok'){location.reload()}
                })
           })
                  
        })
    </script>
</body>
</html>
